#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <stdarg.h>
#ifdef WIN32
#include <Windows.h>
#include <time.h>
#include <WinBase.h>
#else
#include <sys/time.h>
#endif

extern "C" void S_Print (char *error, ...)
{
    va_list	argptr;

    // Message first.
    va_start (argptr,error);
    vfprintf (stderr,error,argptr);
    fprintf (stderr, "\n");
    va_end (argptr);

    fflush( stderr );
}

extern "C" unsigned long  S_GetTime (void)
{
#ifdef WIN32
	unsigned long t= GetTickCount();
	return t;
#else
	struct timeval	tp;
    gettimeofday(&tp, 0);
    return (tp.tv_sec * 1000 + tp.tv_usec / 1000);
#endif 

}

extern "C" int GETUPTIMEMS()
{
	return S_GetTime();
}

extern "C" char* STRUPPER(char* s)
{
	int len = strlen(s);

	for (int i = 0; i < len; i++)
	{
		if (s[i] >= 'a' && s[i] <= 'z')
		{
			s[i] = 'A' - 'a' + s[i];
		}
	}

	return s;
}

extern "C" char* STRLOWER(char* s)
{
	int len = strlen(s);

	for (int i = 0; i < len; i++)
	{
		if (s[i] >= 'A' && s[i] <= 'Z')
		{
			s[i] = 'a' - 'A' + s[i];
		}
	}

	return s;
}

//extern "C" void unlink(const char* filename)
//{
//}

extern "C" void ASSERT(int x, char *file, int line,char *s)
{
	if(!x){
		//char msg[64];
		S_Print("%s\n line:%d\n%s",file, line, s);
		exit(-1);
	}
}
